home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6369 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! Please! Why doesn't this work
  5. Date: 24 Feb 1996 00:56:53 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb23175653@qcd.lanl.gov>
  8. References: <Pine.ULT.3.91a.960215131933.614A-100000@red5.cac.washington.edu>
  9.     <4geqvd$jse@hpbblb.bbn.hp.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: Matthias Dittrich's message of 21 Feb 1996 10:08:45 GMT
  14.  
  15. In article <4geqvd$jse@hpbblb.bbn.hp.com>
  16. Matthias Dittrich <matti> writes:
  17.  
  18. <snip>
  19. MD: You must allocate more memory because these are the bytes to be allocated:
  20. MD:     solution_array = (char **) malloc(size * sizeof(char **));
  21. MD:                                           ^^^^^^^^^^^^^^^^^^  
  22.  
  23. I have not followed the context, but this statement cannot be desired!
  24.  
  25. First, loose the cast and #include <stdlib.h>.
  26.  
  27. Next write it as
  28.   solution_array = malloc(size * sizeof *solution_array)
  29.  
  30. <snip>
  31. MD: here too:
  32. MD:            solution_array[row] = (char *) malloc(size * sizeof(char *));
  33. MD:                                                      ^^^^^^^^^^^^^^^^^
  34.  
  35. Here too:
  36.  
  37. solution_array[row] = malloc(size * sizeof *solution_array[row]);
  38.  
  39. Cheers
  40. Tanmoy
  41. --
  42. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  43. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  44. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  45. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  46. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  47. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  48.